package com.shao.web;

import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import com.shao.utils.Methods;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: SJP
 * Date: 2021/6/5
 * Time: 15:49
 * Description: No Description
 */
public class AjaxServlet extends BaseServlet {

    protected void jQuerySerialize(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String file =  req.getParameter("file");
        System.out.println(file);
        //获取的是json串
        String datafromFile = Methods.getDatafromFile(file);
        System.out.println(datafromFile);
//        // json格式的字符串
//        Gson gson = new Gson();
//        String data = gson.toJson(datafromFile);
        resp.getWriter().write(datafromFile);
    }
    protected void jQuerySerializeUpdata(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String file =  req.getParameter("file");
        //获取的是json串
        //String datafromFile = Methods.getDatafromFile(file);
        //Object parse = JSON.parse(datafromFile);
        String data = "{\n" +
                "    \"interface\":{\n" +
                "        \"apikey\":\" "+req.getParameter("apikey")+ "\",\n" +
                "        \"face_group\":\""+req.getParameter("face_group")+"\",\n" +
                "        \"EffectiveTime\":"+req.getParameter("EffectiveTime")+",\n" +
                "        \"secretkey\":\"mfpF8Xwyz8cTOumhhrs6PxCMElpCg62n\",\n" +
                "        \"score\":70,\n" +
                "        \"appid\":\"19956741\",\n" +
                "        \"help\":\"使用云端服务所需要的配置\",\n" +
                "        \"autostart\":true,\n" +
                "        \"imagefiles\":\"http://127.0.0.1:1891/?action=snapshot\"\n" +
                "    },\n" +
                "    \"lastBrush\":{\n" +
                "        \"score\":96.6122970581,\n" +
                "        \"user_id\":\"20110032\",\n" +
                "        \"datetime\":\"2020-07-19 16:07:49\"\n" +
                "    }\n" +
                "}";
        System.out.println(1+req.getParameter("apikey"));
        Methods.saveDataToFile(file,data);
    }

    }
